from django import forms

from online_shop.products.models import products,categories , sub_categories

STATUS_CHOICES = (
    (0, 'Normal'),
    (1, 'Hidden'),
)
CHANGE_TYPE_CHOICE = (
    ('add', "Add to"),
    ('change', "Change"),
)
WEIGHT_CHOICE = ((-5,-5),(-4,-4),(-3,-3),(-2,-2),(-1,-1),(0,0),(1,1),(2,2),(3,3),(4,4),(5,5))

class ProductForm(forms.ModelForm): 
    category = forms.ModelChoiceField(queryset=categories.objects.all(),required=True,)
    subcategory = forms.ModelChoiceField(queryset=sub_categories.objects.all(),required=True,)
    status = forms.ChoiceField(STATUS_CHOICES)
    shortDescription = forms.CharField(widget=forms.TextInput(attrs={'size':40}),required=True,)
    description = forms.CharField(widget=forms.Textarea(attrs={'class':'ckeditor'}),required=True,)
    #image = forms.ImageField(required=False)
    
    def __init__(self, *args, **kwargs):
        super(ProductForm, self).__init__(*args, **kwargs)
        self.fields['category'].queryset = categories.objects.all()
        self.fields['category'].label_from_instance = lambda obj: obj.name
        self.fields['subcategory'].queryset = sub_categories.objects.all()
        self.fields['subcategory'].label_from_instance = lambda obj: obj.name
    class Meta:
        model = products

class InventoryManagementForm(forms.Form):
    amount = forms.IntegerField(min_value=0)
    changeType = forms.CharField(CHANGE_TYPE_CHOICE)
    
class CategoryForm(forms.ModelForm):
    weight = forms.ChoiceField(WEIGHT_CHOICE)
    class Meta:
        model = categories

class SubcategoryForm(forms.ModelForm):
    weight = forms.ChoiceField(WEIGHT_CHOICE)
    def __init__(self, *args, **kwargs):
        super(SubcategoryForm, self).__init__(*args, **kwargs)
        self.fields['category'].queryset = categories.objects.all()
        self.fields['category'].label_from_instance = lambda obj: obj.name
    class Meta:
        model = sub_categories

    